package form_request

import (
	"cms/utils/convert"
	"github.com/gin-gonic/gin"
)

// GetPageParams 获取分页参数
func GetPageParams(ctx *gin.Context) (offset int, limit int) {
	queryPage := convert.StrToInt(ctx.Query("page"))
	queryLimit := convert.StrToInt(ctx.Query("limit"))
	if queryLimit <= 0 {
		limit = 10
	} else {
		limit = queryLimit
	}
	if queryLimit > 100 {
		limit = 100
	}
	if queryPage <= 0 {
		offset = 0
	} else {
		offset = (queryPage - 1) * limit
	}
	return offset, limit
}
